package com.veo.service.Imp;

import com.github.pagehelper.PageHelper;
import com.veo.dao.RolesDao;
import com.veo.domain.Permission;
import com.veo.domain.Role;
import com.veo.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

@Service("roleService")
public class ReoleServiceImpl implements RoleService {

    @Autowired
    private RolesDao rolesDao;

    public List<Role> findAllRole(int page, int size, String searcherName) {
        //实现分页
        PageHelper.startPage(page,size);
        return rolesDao.findAllRole(searcherName);
    }


    public int addRole(Role role) {
        return rolesDao.addRole(role);
    }

    public Role findById(String roleId) {
        return rolesDao.findById(roleId);
    }

    public List<Permission> findPermissionToRole(String roleId) {
        return rolesDao.findPermissionToRole(roleId);
    }

    public int addPermissionToRole(String roleId, String[] permissionId) {
        int count=0;
        for (String id : permissionId) {
            count = rolesDao.addPermissionToRole(roleId, id);
        }
        return count;
    }

    public Role findRoleAndPermissions(String roleId) {
        return rolesDao.findRoleAndPermissions(roleId);
    }

    public int deleteRolePermissionId(String id) {
        return rolesDao.deleteRolePermissionId(id);
    }

    public int deleteRoleById(String id) {
        return rolesDao.deleteRoleById(id);
    }
}
